package com.medicine.service.impl;

import com.medicine.service.IUserService;
import com.medicine.model.User;
import com.medicine.dao.inter.UserDao;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Map;

/** 
 * 业务接口实现
 * @author jim 
 * @date 2017-10-26
 * 大尚 
 **/ 
@Service("userService")
public class UserServiceImpl implements IUserService {

   /*******************start********************/
	 @Resource
	 private UserDao userDao;

	 /**
	  * 根据模型中不为Null或''的属性进行删除
	 */
	 @Transactional
	 public int deleteByModel(User model){

	    int count=0;
	    try {
	      count=userDao.deleteByModel(model);
	    } catch (Exception e){
	       System.out.println("删除失败");
	       e.printStackTrace();
	    }
	    return count;
	 }

	 /**
	  * 根据主键删除
	 */
	 @Transactional
	 public int deleteByPrimaryKey(String id){

	    int count=0;
	    try {
	      count=userDao.deleteByPrimaryKey(id);
	      return count;
	    } catch (Exception e){
	       System.out.println("根据主键删除失败");
	       e.printStackTrace();
	    }
	    return count;
	 }

	 /**
	  * 根据主键修改模型中属性不为Null的值
	 */
	 @Transactional
	 public int updateByPrimaryKey(User model){

	    int count=0;
	    try {
	      count=userDao.updateByPrimaryKey(model);
	      return count;
	    } catch (Exception e){
	       System.out.println("根据主键删除失败");
	       e.printStackTrace();
	    }
	    return count;
	 }

	 /**
	  * 根据主键查询模型
	 */
	 public User selectByPrimaryKey(String id){

	    User model=null;
	    try {
	      model=userDao.selectByPrimaryKey(id);
	    } catch (Exception e){
	       System.out.println("根据主键查询失败");
	       e.printStackTrace();
	    }
	    return model;
	 }

	 /**
	  * 根据模型中不为Null 或者 ‘’的属性进行查询
	 */
	 public List<User> selectByModel(User model){

	    List<User> models=null;
	    try {
	      models=userDao.selectByModel(model);
	    } catch (Exception e){
	       System.out.println("根据模型查询失败");
	       e.printStackTrace();
	    }
	    return models;
	 }

	 /**
	  * 插入模型
	 */
	 @Transactional
	 public int insert(User model){

	    int count=0;
	    try {
	      count=userDao.insert(model);
	    } catch (Exception e){
	       System.out.println("插入失败");
	       e.printStackTrace();
	    }
	    return count;
	 }

	 /**
	  * 根据map进行分页查询
	 */
	 public List<User> selectPageByMap(Map<String,Object> model){

	    List<User> models=null;
	    try {
	      models=userDao.selectPageByMap(model);
	    } catch (Exception e){
	       System.out.println("根据map进行分页查询失败");
	       e.printStackTrace();
	    }
	    return models;
	 }

	 /**
	  * 根据map进行分页查询
	 */
	 public long selectCountByMap(Map<String,Object> model){

	    long  num=0;
	    try {
	      num=userDao.selectCountByMap(model);
	    } catch (Exception e){
	       System.out.println("根据map进行分页查询失败");
	       e.printStackTrace();
	    }
	    return num;
	 }

   /*******************end********************/
}